// 登录时的判断
function Login (){}
$.extend(Login.prototype,{
    init :function(){
        this.phone = $(".phoness ");
        this.password = $(".pwds ");
        this.btn      = $("#login");
        this.error    = $(".error");
        this.error_txt=$(".error_txt");
        this.list = localStorage.getItem("user");
        this.btn.on("click",$.proxy(function(){
            this.validata()
        },this))
    },
    //先进行是否有localStorage的存在 再判断手机号是否存在  存在再判断密码是否正确
    validata :function(){
        this.error.css("display","none");
        if(!this.phone.val() && !this.password.val()){
            this.error.css("display","block")
            this.error_txt.html("请填写完整信息")
            return false;
        }
        if(!this.list){
            alert("账号不存在，请注册!");
            return false;
        }
        if(this.list){
            var list = JSON.parse(this.list);
            var phone = this.phone.val();
            var password = this.password.val();
            var flag  = false;
            $.each(list,$.proxy(function(index,item){
                if(phone == item.phone){
                    flag = true;
                    if(password == item.password){
                        item.status = true ;
                        localStorage.setItem("user",JSON.stringify(list));
                        location.href = "../html/index.html";
                    }else{
                        console.log(1);
                        this.error.css("display","block")
                        this.error_txt.html("密码有误")
                        return false;
                    }
                }
            },this))
            if(!flag){
                this.error.css("display","block")
                this.error_txt.html("账号不存在，请注册!")
                return false;
            }
        }
    }
})
export default new Login();